//
//  UIImage+ProfileImage.m
//  百思不得姐
//
//  Created by 胥鸿儒 on 16/6/20.
//  Copyright © 2016年 xuhongru. All rights reserved.
//

#import "UIImage+ProfileImage.h"

@implementation UIImage (ProfileImage)


- (void)profileImageWithProfileImageBlock:(ProfileImageBlock)profileImageBlock
{
//   UIImage *blockImage = nil;

//    ImageBlock  imageBlock = ^(UIImage *image){
//        return image;
//    };
    dispatch_async(dispatch_get_global_queue(0, 0), ^{

         //开启图片上下文
         UIGraphicsBeginImageContextWithOptions(self.size, NO, 0);
         //获取当前上下文
         CGContextRef ctx  = UIGraphicsGetCurrentContext();
         //设置画的范围
         CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
         //绘制路径
         CGContextAddEllipseInRect(ctx, rect);
         //裁剪
         CGContextClip(ctx);
         //绘制裁剪后的图片
         [self drawInRect:rect];
         //获取裁剪后的图片
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
         //有开有关
         UIGraphicsEndImageContext();
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            profileImageBlock(image);
        });
     });

}

@end
